import { GraphModel, h, NodeConfig, RectNode, RectNodeModel } from '@logicflow/core';
import { getBpmnId } from '@logicflow/extension/es/bpmn/getBpmnId';

class ServiceTaskModel extends RectNodeModel {
  static extendKey = 'ServiceTaskModel';
  constructor(data: NodeConfig, graphModel: GraphModel) {
    if (!data.id) {
      data.id = `Activity_${getBpmnId()}`;
    }
    super(data, graphModel);
  }
}

class ServiceTaskView extends RectNode {
  static extendKey = 'ServiceTaskNode';
  getLabelShape(): h.JSX.Element {
    const { model } = this.props;
    const { x, y, width, height } = model;
    const style = model.getNodeStyle();
    return h(
      'svg',
      {
        x: x - width / 2 + 2,
        y: y - height / 2 + 2,
        width: 32,
        height: 32,
        viewBox: '0 0 1024 1024',
      },
      h('path', {
        fill: style.stroke,
        d:
          'M422.781952 224.345088c-0.023552 18.942976 0.00512 37.886976 0.054272 56.829952-16.155648 4.570624-30.918144 10.948608-44.859392 18.761728l-40.745984-40.256-76.188672 76.630016 40.742912 40.249344a201.485312 201.485312 0 0 0-18.305024 44.667904l-57.7152 0.10496v107.92448l58.318336-0.210432c5.332992 21.144576 16.939008 40.1536 28.498944 57.150976V493.104128l-50.97728 0.182784V457.10848l50.723328-0.09216 2.84672-14.424064c4.15232-21.035008 12.37504-41.087488 24.188928-59.029504l8.08192-12.274176-35.636736-35.206144 25.648128-25.79712 35.70176 35.273216 12.14976-8.108032c18.567168-12.250112 38.875648-20.461056 59.126272-24.737792l14.31552-2.97216-0.128-49.55392h36.846592l-0.285184 49.295872h96.683008c-9.069056-10.825728-46.65344-24.912896-60.676096-28.837888l0.32512-56.297984c-40.1408-0.001024-71.61088 0.002048-108.73344-0.001024z m101.968896 103.248896l0.146944 56.827904c-16.155648 4.570624-30.918144 10.948096-44.859904 18.76224l-40.747008-40.256-76.188672 76.630016 40.743936 40.248832a201.47968 201.47968 0 0 0-18.306048 44.668928l-57.714176 0.103936v107.92448l58.3168-0.209408c4.590592 16.003584 10.95424 30.6176 18.752512 44.413952l-41.72544 41.562112 77.03808 75.714048 41.574912-41.381888c14.24128 7.907328 29.37856 14.047232 45.073408 18.319872l0.026624 58.733056c37.064704 0.324608 76.527104 0.157184 108.204032 0.1536v-59.42784c16.167936-4.558848 30.976512-10.9824 44.921344-18.79296l41.540608 40.957952 76.23936-76.53376-41.62816-41.022976a201.955328 201.955328 0 0 0 18.329088-44.748288l56.514048-0.348672v-107.820032l-57.148416 0.34816c-4.593664-16.018944-10.86464-30.534144-18.766848-44.422144l39.485952-39.587328-76.99456-75.84256-39.435264 39.56992a204.102144 204.102144 0 0 0-44.89216-18.247168l0.324096-56.297984h-108.825088z m35.93216 35.84h36.847104l-0.28416 49.296896 14.554112 2.855936c21.131264 4.1472 41.38496 12.35968 59.39968 24.101376l12.1984 7.950848 34.414592-34.53184 25.916416 25.52832-34.46272 34.551296 8.291328 12.240384c12.16768 18.366464 20.238848 38.2208 24.795136 58.66496l2.998272 14.341632 49.80736-0.302592v36.14208l-49.529344 0.30464-2.845184 14.342144a166.198272 166.198272 0 0 1-24.217088 59.083776l-8.091136 12.291072 36.484096 35.954176-25.644032 25.74336-36.48768-35.976192-12.12928 8.057856c-18.5728 12.137472-38.719488 20.542976-59.045888 24.68352l-14.409728 2.878464v52.33408c-9.851392 0.023552-20.598272 0.008192-36.54144-0.014336l-0.02304-51.941888-14.474752-2.826752c-21.16096-4.132352-41.381376-12.307456-59.364864-24.098304l-12.162048-7.973888-36.628992 36.45952-25.92-25.475584 36.67968-36.536832-8.369664-12.290048c-12.178944-18.326528-20.235776-38.201344-24.800256-58.621952l-2.9952-14.298112-50.976768 0.18176v-36.17792l50.723328-0.092672 2.84672-14.422016c4.15232-21.03552 12.37504-41.089024 24.188928-59.03104l8.08192-12.2752-35.63776-35.206144 25.648128-25.796608 35.702784 35.272704 12.14976-8.107008c18.59072-12.17024 38.318592-20.244992 59.126272-24.736768l14.31552-2.97216-0.128512-49.554944z m19.028992 131.687936c-44.363264 0-80.711168 36.348928-80.711168 80.71168 0 44.363776 36.347904 80.710656 80.711168 80.710656s80.711168-36.34688 80.711168-80.710144-36.347904-80.71168-80.711168-80.71168z m0 35.84c24.993792 0 44.871168 19.8784 44.871168 44.87168 0 24.994304-19.877376 44.870656-44.871168 44.870656-24.993792 0-44.870144-19.876352-44.870144-44.870144s19.87584-44.87168 44.870144-44.87168z',
      }),
    );
  }
  getShape(): h.JSX.Element {
    const { model } = this.props;
    const { x, y, width, height, radius } = model;
    const style = model.getNodeStyle();
    return h('g', {}, [
      h('rect', {
        x: x - width / 2,
        y: y - height / 2,
        rx: radius,
        ry: radius,
        width,
        height,
        ...style,
      }),
      this.getLabelShape(),
    ]);
  }
}

const ServiceTask = {
  type: 'bpmn:serviceTask',
  view: ServiceTaskView,
  model: ServiceTaskModel,
};

export { ServiceTaskView, ServiceTaskModel };
export default ServiceTask;
